'use strict';
const path =require('path');

module.exports = app => {
  class UploadController extends app.Controller {
    * image(ctx) {
      const stream= yield  ctx.getFileStream();
      const name=stream.fields.path+Date.now() + path.basename(stream.filename);
      let result;
      try{
        result=yield ctx.oss.put(name,stream);
      }catch (error){
        yield sendToWormhole(stream);
        throw  error;
      }
      // var mediaId=this.ctx.request.body.mediaId;
      // var path=this.ctx.request.body.path;
      // var uploadResult=yield this.ctx.oss.put(path,result.data);
      // yield this.ctx.body={
      //   url:uploadResult.url
      // };
        ctx.body={
          "path":result.url
        }
    }
  }
  return UploadController;
};
